const moment = require("moment");
function factory(sourConsole, color = 42) {
  return function (...args) {
    if (typeof args[0] == "string" && args[0].indexOf("%s") != -1) {
      let arr = args[0].split("%s");
      let str = "";
      arr.forEach((t, i) => {
        str += t;
        if (args.length >= i + 2) {
          str += args[i + 1];
        }
      });
      args = [str];
    }
    const timeStr = moment().format("MM-DD HH:mm:ss");
    args.unshift("\033[" + color + ";37m " + timeStr + " \033[0m");
    sourConsole(...args);
  };
}
global.console.log = factory(console.log, 42);
global.console.warn = factory(console.warn, 41);
global.console.error = factory(console.error, 45);
